import 'package:encrypt/encrypt.dart';
import 'package:flutter/services.dart';
import 'dart:convert';
import 'package:pointycastle/asymmetric/api.dart';
class Encrypt {

  /// 解密
  static Future<String> decrypt(String decoded) async {
    final parser = RSAKeyParser();
    String privateKeyString = await rootBundle.loadString('assets/rsa_key/rsa_private_key.pem');
    print('privateKeyString=$privateKeyString'); // 注意这一行的输出
    final privateKey = parser.parse(privateKeyString) as RSAPrivateKey;
    final encrypter = Encrypter(RSA(privateKey: privateKey));
    return encrypter.decrypt(Encrypted.fromBase64(decoded));
  }

  ///Aes解密
  static String decryptAes(String _keyAes,String code) {
    final encrypter = Encrypter(AES( Key.fromUtf8(_keyAes),mode: AESMode.ecb));
    return encrypter.decrypt(Encrypted.fromBase64(code));
  }

}
